package com.g4.shoppingsingle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.g4.shoppingsingle.mapper.DdOrderInfoMapper;
import com.g4.shoppingsingle.mapper.DdUsersInfoMapper;
import com.g4.shoppingsingle.model.DdOrderInfo;
import com.g4.shoppingsingle.model.DdUsersInfo;
import com.g4.shoppingsingle.service.IDdOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-10-27
 */
@Service
public class DdOrderInfoServiceImpl extends ServiceImpl<DdOrderInfoMapper, DdOrderInfo> implements IDdOrderInfoService {

    //用户表
    @Autowired
    private DdUsersInfoMapper ddUsersInfoMapper;

    //订单表
    @Autowired
    private DdOrderInfoMapper ddOrderInfoMapper;

    @Override
    public List<DdOrderInfo> getOrders(String username) {
        //1、先通过用户名 去查 用户
        QueryWrapper<DdUsersInfo> query = new QueryWrapper<>();
        query.eq("user_name",username);  // where user_name = "张三";
        List<DdUsersInfo> ddUsersInfos = ddUsersInfoMapper.selectList(query);
        //当前登录的用户
        DdUsersInfo model = ddUsersInfos.get(0);

        //2、通过用户id去订单表查订单信息
        QueryWrapper<DdOrderInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",model.getId());    // where user_id = 2;
        List<DdOrderInfo> orders=ddOrderInfoMapper.selectList(wrapper);
        return orders;
    }


}
